package com.bh.web.controller.wms;

import com.bh.common.annotation.Log;
import com.bh.common.core.controller.BaseController;
import com.bh.common.core.domain.AjaxResult;
import com.bh.common.core.page.TableDataInfo;
import com.bh.common.enums.BusinessType;
import com.bh.common.utils.poi.ExcelUtil;
import com.bh.wms.domain.WmsWarehouseZone;
import com.bh.wms.service.IWmsWarehouseZoneService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 库区管理接口
 *
 * @author GPT
 */
@Api(tags = "库区管理")
@RestController
@RequestMapping("/wms/zone")
public class WmsWarehouseZoneController extends BaseController {

    @Autowired
    private IWmsWarehouseZoneService warehouseZoneService;

    @ApiOperation("分页查询库区")
    @PreAuthorize("@ss.hasPermi('wms:zone:list')")
    @GetMapping("/list")
    public TableDataInfo list(WmsWarehouseZone query) {
        startPage();
        List<WmsWarehouseZone> list = warehouseZoneService.selectWmsWarehouseZoneList(query);
        return getDataTable(list);
    }

    @ApiOperation("导出库区")
    @PreAuthorize("@ss.hasPermi('wms:zone:export')")
    @Log(title = "库区管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsWarehouseZone query) {
        List<WmsWarehouseZone> list = warehouseZoneService.selectWmsWarehouseZoneList(query);
        ExcelUtil<WmsWarehouseZone> util = new ExcelUtil<>(WmsWarehouseZone.class);
        util.exportExcel(response, list, "库区数据");
    }

    @ApiOperation("获取库区详情")
    @PreAuthorize("@ss.hasPermi('wms:zone:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return success(warehouseZoneService.selectWmsWarehouseZoneById(id));
    }

    @ApiOperation("新增库区")
    @PreAuthorize("@ss.hasPermi('wms:zone:add')")
    @Log(title = "库区管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsWarehouseZone entity) {
        return toAjax(warehouseZoneService.insertWmsWarehouseZone(entity));
    }

    @ApiOperation("修改库区")
    @PreAuthorize("@ss.hasPermi('wms:zone:edit')")
    @Log(title = "库区管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmsWarehouseZone entity) {
        return toAjax(warehouseZoneService.updateWmsWarehouseZone(entity));
    }

    @ApiOperation("删除库区")
    @PreAuthorize("@ss.hasPermi('wms:zone:remove')")
    @Log(title = "库区管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(warehouseZoneService.deleteWmsWarehouseZoneByIds(ids));
    }
}

